package com.kehao.leetcode.jzoffer;


import java.util.HashSet;
import java.util.Set;

public class JZSolution064 {
    private static class MagicDictionary {

        /** Initialize your data structure here. */
        Set<String> allStrSet = new HashSet<>();
        public MagicDictionary() {

        }

        public void buildDict(String[] dictionary) {
            for (String s : dictionary) {
                allStrSet.add(s);
            }
        }

        private boolean magic(String s1,String s2){
            if(s1.length()!=s2.length()) return false;
            if(s1==s2) return false;
            int count = 0;
            for (int i = 0; i < s1.length()&&count<=1; i++) {
                if(s1.charAt(i)!=s2.charAt(i)){
                    count++;
                }
            }
            return count ==1;
        }

        public boolean search(String searchWord) {
            for (String s : allStrSet) {
                if(magic(s,searchWord)){
                    return true;
                }
            }
            return false;
        }
    }
}
